package Work;

import java.io.*;
import java.util.*;
public class WordStatics {
    Vector<String> allWord,noSameWord;
    File file =new File("src/chapter10/实验1输入输出流/english.txt");
    Scanner sc =null;
    String regrex;
    WordStatics(){
        allWord = new Vector<String>();
        noSameWord = new Vector<String>();
        regrex = "[\\s\\d\\p{Punct}]+";
        try {
            sc = new Scanner(file);
            sc.useDelimiter(regrex);
        } catch (Exception e) {
            System.out.println(e.toString());
        }
    }
    void setFileName(String name) {
        file = new File(name);
        try {
            sc = new Scanner(file);
            sc.useDelimiter(regrex);
        } catch (IOException e) {
            System.out.println(e.toString());
        }
    }
    public void wordStatic() {
        try {
            while(sc.hasNext()) {
                String word = sc.next();
                allWord.add(word);
                if(!noSameWord.contains(word)) {
                    noSameWord.add(word);
                }
            }
        } catch (Exception e) {
        }
    }
    public Vector<String> getAllWord(){
        return allWord;
    }
    public Vector<String> getNoSameWord(){
        return noSameWord;
    }

}

